package com.shanglv.web.common.directive;

import java.util.Iterator;
import java.util.Map;

public class BaseDirective {

    protected final String ATTR_NAME = "name";
    protected final String ATTR_URL = "url";

    protected final String APPEND_NAME = "append";

    protected final String DEFAULT_ENCODING = "UTF-8";

    public String getParams(Map<String, Object> params, String param) {
        String value = null;
        if (null != params && !params.isEmpty()) {
            String key = getParam(params, param);
            Object tempValue = params.get(key);
            value = (null== tempValue)?null:tempValue.toString();
        }
        return value;
    }

    private String getParam(Map<String, Object> params, String param) {
        Iterator<String> iterator = params.keySet().iterator();
        while (iterator.hasNext()) {
            String tempKey = iterator.next();
            if (param.equalsIgnoreCase(tempKey)) {
                return tempKey;
            }
        }
        return param;
    }
}
